<?php

namespace App\Models;

use Illuminate\Notifications\Notifiable;
use Illuminate\Foundation\Auth\User as Authenticatable;
use Tymon\JWTAuth\Contracts\JWTSubject;

class User extends Authenticatable implements JWTSubject
{
    use Notifiable;

    /**
     * The attributes that are mass assignable.
     *
     * @var array
     */
    protected $fillable = [
        'name', 'email', 'password',
    ];

    /**
     * The attributes that should be hidden for arrays.
     *
     * @var array
     */
    protected $hidden = [
        'password', 'remember_token',
    ];

    /**
     * Get the identifier that will be stored in the subject claim of the JWT.
     * 获取将存储在JWT的主题声明中的标识符。
     * @return mixed
     */
    public function getJWTIdentifier()
    {
        return $this->getKey();
    }

    /**
     * Return a key value array, containing any custom claims to be added to the JWT.
     * 返回一个键值数组，包含要添加到JWT的任何自定义声明。
     * @return array
     */
    public function getJWTCustomClaims()
    {
        return [];
    }

    public function getList()
    {
        $pageSize = empty($params['page_size']) ? config('sdblog.pageSize') : $params['page_size'];
        $page = empty($params['page']) ? 1 : $params['page'];
        return $this->orderBy('created_at', "desc")
            ->paginate($pageSize, ["*"], 'page', $page);
    }

    public function changeEnable($id, $status)
    {
        return $this->where("id", $id)->update(["is_enable" => $status]);
    }

    public function getMonthCount()
    {
        return $this->where("created_at", ">=", date("Y-m"))
            ->where("created_at", "<", date("Y-m", strtotime("+1 month")))
            ->count();
    }

}
